package com.kingja.loadsir.callback;


import com.kingja.loadsir.utils.TextUtils;
import ohos.agp.components.*;
import ohos.app.Context;
import com.kingja.loadsir.ResourceTable;


public class HintCallback extends Callback {

    private String title;
    private String subTitle;
    private int imgResId;
    private int titleStyleRes;
    private int subTitleStyleRes;

    public HintCallback(Builder builder) {
        this.title = builder.title;
        this.subTitle = builder.subTitle;
        this.imgResId = builder.imgResId;
        this.subTitleStyleRes = builder.subTitleStyleRes;
        this.titleStyleRes = builder.titleStyleRes;
    }

    @Override
    protected int onCreateView() {
        return 0;
    }

    @Override
    protected Component onBuildView(Context context) {
        return LayoutScatter.getInstance(context).parse(ResourceTable.Layout_layout_hint, null, false);
    }

    @Override
    protected void onViewCreate(Context context, Component view) {

        if (imgResId != -1) {
            Image ivImage = (Image) view.findComponentById(ResourceTable.Id_image);
            ivImage.setPixelMap(imgResId);

        }
        if (!TextUtils.isEmpty(title)) {
            Text tvTitle = (Text) view.findComponentById(ResourceTable.Id_title);
            tvTitle.setText(title);

        }
        if (!TextUtils.isEmpty(subTitle)) {
            Text tvSubtitle = (Text) view.findComponentById(ResourceTable.Id_sub_title);
            tvSubtitle.setText(subTitle);
        }
    }

    public static class Builder {
        private String title;
        private String subTitle;
        private int imgResId = -1;
        private int subTitleStyleRes = -1;
        private int titleStyleRes = -1;

        public Builder setHintImg(int imgResId) {
            this.imgResId = imgResId;
            return this;
        }

        public Builder setTitle(String title) {
            return setTitle(title, -1);
        }

        public Builder setTitle(String title, int titleStyleRes) {
            this.title = title;
            this.titleStyleRes = titleStyleRes;
            return this;
        }

        public Builder setSubTitle(String subTitle) {
            return setSubTitle(subTitle, -1);
        }

        public Builder setSubTitle(String subTitle, int subTitleStyleRes) {
            this.subTitle = subTitle;
            this.subTitleStyleRes = subTitleStyleRes;
            return this;
        }

        public HintCallback build() {
            return new HintCallback(this);
        }
    }
}